# -*- coding: utf-8 -*-
import os
import json 
from google.appengine.ext import webapp as webapp2
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import login_required
from google.appengine.api import users


class MainPage(webapp2.RequestHandler):
  #@login_required   
  def get(self):
    params = {'message': 'hello'}
    fpath = os.path.join(os.path.dirname(__file__),'home.html')
    html = template.render(fpath,params)
    self.response.headers['Content-Type'] = 'text/html'
    self.response.out.write(html)
 


class AjaxTest(webapp2.RequestHandler):
  def get(self):
    user = users.get_current_user()
    data = {"name":user.nickname(),"email":user.email(),"id":user.user_id()}
    json_data = json.dumps(data)
    self.response.headers['Content-Type'] = 'application/json'
    self.response.out.write(json_data)


application = webapp2.WSGIApplication([
  ('/', MainPage),
  ('/ajaxtest', AjaxTest)],
   debug=True)
